#
# Makefile
#
export GNUMAKEFLAGS=-j12  #12线程并行编译
PWD=`pwd`
SDK_LIBS=../../project/release/nvr/i2m/common/glibc/8.2.1/mi_libs/dynamic
SDK_LIBS_STATIC=$(patsubst %dynamic,%static,$(SDK_LIBS))
PLAT_DEPENDENT_LIB=-lmi_gfx -lmi_sys -lmi_common -ldl 
PLAT_DEPENDENT_LIB_EX= -lmi_disp -lmi_panel 
MINIGUI_LIBS= -ljpeg -lz 
SDK_INCS=../../project/release/include
UAPI_INCS=../../project/kbuild/4.9.84/i2m/include/uapi/mstar
INCLUDES=./common

# LIBVAR   = -lmytest             
# LIBPATH  = -L./dynamiclib/libs         
LDFLAGS+=-L$(SDK_LIBS)  -L$(SDK_LIBS_STATIC) 
LDFLAGS+=-L$(PWD)/lib -L/usr/local/lib  -L./lib
LDFLAGS+=-L$(PWD)/lib/freetype2 -L./lib -lfreetype
# LDFLAGS+=-L$(PWD)/library/lib -L./lib -lfreetype
STDLIBS:=   -ldl  -lm -lz -lpthread -lmi_common -lmi_sys -lmi_wlan -lcjson -Wl,--hash-style=gnu 
LIBS:=-Wl,-Bdynamic ${MINIGUI_LIBS} ${PLAT_DEPENDENT_LIB_EX} ${PLAT_DEPENDENT_LIB} -Wl,-Bdynamic $(STDLIBS)
#CFLAGS=-rdynamic -funwind-tables -I. -I$(SDK_INCS) -I$(PWD)/inc -I$(UAPI_INCS) -I$(INCLUDES)
#-I$(PWD)/library/include -I$(PWD)/library/include/ctrl -I$(PWD)/library/include/libpng16/ -I/usr/local/include -I$(UAPI_INCS)

# CC := gcc
CC := arm-linux-gnueabihf-gcc
LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= ${shell pwd}
CFLAGS += -rdynamic -funwind-tables -I. -I$(SDK_INCS) -I$(PWD)/inc -I$(UAPI_INCS) -I$(INCLUDES) -O3 -g0 -I$(LVGL_DIR)/ -Wall -Wshadow \
-Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wall -Wextra -Wno-unused-function -Wundef -Wno-error=strict-prototypes -Wpointer-arith \
-fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits \
-Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wno-switch-enum -Wreturn-type -Wmultichar \
-Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered \
-Wdeprecated -Wempty-body -Wtype-limits -Wstack-usage=2048 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers \
-Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess \
-Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar \
-Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare -Wno-format-truncation
# -Wno-unused-variable
# -Wswitch-enum
LDFLAGS += $(LIBS)  
BIN = 27.pro
# BIN = coating.pro


#Collect the files to compile
# MAINSRC = ./main.c
# MAINSRC = ./src/main/main.c

include $(LVGL_DIR)/$(LVGL_DIR_NAME)/lvgl.mk
include $(LVGL_DIR)/library/library.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
include $(LVGL_DIR)/lv_examples/lv_examples.mk
include $(LVGL_DIR)/src/src.mk
# include $(LVGL_DIR)/lv_lib_png/lv_lib_png.mk

OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

OUTPUT_DIR = build
BIN_DIR = $(OUTPUT_DIR)/bin
## MAINOBJ -> OBJFILES


# mkdir -p $(LVGL_DIR)/$(OUTPUT_DIR) $(LVGL_DIR)/$(BIN_DIR)
%.o: %.c
	@$(CC) -g $(CFLAGS) -c $< -o $@
# @$(CC)  $(CFLAGS) -c $< -o $(LVGL_DIR)/build/$@
	@echo -e $<
    
default: $(AOBJS) $(COBJS) $(MAINOBJ)
# create output directory
	@mkdir -p $(LVGL_DIR)/$(OUTPUT_DIR) $(LVGL_DIR)/$(BIN_DIR)
	@$(CC) -g -o $(BIN_DIR)/$(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS) $(FFMPEG_LIB) 
#	@mv *.o $(LVGL_DIR)/$(OUTPUT_DIR)
# mv $(OUTPUT_DIR)/$(BIN) $(LVGL_DIR)/$(BIN_DIR)

clean: 
	rm -rf build/*
	@find . -name "*.o" | xargs rm -rf

test:
#	@echo $(SRCS)
#	@echo $(CFLAGS)
#	@echo $(VPATH)
	@echo $(DEPPATH)
#	@echo $(FREETYPE_CFLAGS)
#	@echo $(FREETYPE_LIBS)
#	@echo $(LIBS)
#	@echo $(LDFLAGS)
#	@echo $(LVGL_DIR)
#	@echo $(LVGL_DIR_NAME)
#   @echo $(FREETYPE_INCLUDES)
all: default
